package com.ruoyi.help.service.impl;

import com.ruoyi.help.domain.Evaluate;
import com.ruoyi.help.mapper.EvaluateMapper;
import com.ruoyi.help.service.IEvaluateService;
import com.ruoyi.help.vo.EvaluateVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 帮扶评价Service业务层处理
 *
 * @author ruoyi
 * @date 2023-05-20
 */
@Service
public class EvaluateServiceImpl implements IEvaluateService {
    @Autowired
    private EvaluateMapper evaluateMapper;

    /**
     * 查询帮扶评价
     *
     * @param id 帮扶评价主键
     * @return 帮扶评价
     */
    @Override
    public Evaluate selectEvaluateById(Long id) {
        return evaluateMapper.selectEvaluateById(id);
    }

    /**
     * 查询帮扶评价列表
     *
     * @param evaluate 帮扶评价
     * @return 帮扶评价
     */
    @Override
    public List<Evaluate> selectEvaluateList(Evaluate evaluate) {
        return evaluateMapper.selectEvaluateList(evaluate);
    }

    /**
     * 新增帮扶评价
     *
     * @param evaluateVo 帮扶评价
     * @return 结果
     */
    @Override
    public int insertEvaluate(EvaluateVo evaluateVo) {
        if(StringUtils.isEmpty(evaluateVo.getTeacherName()) || StringUtils.isEmpty(evaluateVo.getStuName())){
            return -5;
        }

        Evaluate evaluate = new Evaluate();
        BeanUtils.copyProperties(evaluateVo, evaluate);
        evaluate.setEvaluateTime(new Date());
        evaluate.setHelpTime(evaluateVo.getOkTime());

        return evaluateMapper.insertEvaluate(evaluate);
    }

    /**
     * 修改帮扶评价
     *
     * @param evaluate 帮扶评价
     * @return 结果
     */
    @Override
    public int updateEvaluate(Evaluate evaluate) {
        return evaluateMapper.updateEvaluate(evaluate);
    }

    /**
     * 批量删除帮扶评价
     *
     * @param ids 需要删除的帮扶评价主键
     * @return 结果
     */
    @Override
    public int deleteEvaluateByIds(Long[] ids) {
        return evaluateMapper.deleteEvaluateByIds(ids);
    }

    /**
     * 删除帮扶评价信息
     *
     * @param id 帮扶评价主键
     * @return 结果
     */
    @Override
    public int deleteEvaluateById(Long id) {
        return evaluateMapper.deleteEvaluateById(id);
    }
}
